# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgbase=lua-cassowary
_rockname=${pkgbase#lua-}
_project=$_rockname.lua
pkgname=("$pkgbase" "lua51-$_rockname" "lua52-$_rockname" "lua53-$_rockname")
pkgver=2.3.2
_rockrel=1 # upstream rockrel 2 is only needed for installing with Luarocks 2.x
pkgrel=1
pkgdesc='The cassowary constraint solver'
arch=(any)
url="https://github.com/sile-typesetter/$_project"
license=(MIT)
_luadeps=(penlight)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
checkdepends=(busted)
_archive="$_project-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('20fe7309f59004ce59e6c65d69ed9993de907267fd0314fc224f40e017d59798')

check() {
	cd "$_archive"
	busted
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}" "${_luadeps[@]/#/${pkgname%-*}-}")
	luarocks --lua-version="$1" --tree="$pkgdir/usr/" \
		make --deps-mode=none --no-manifest "rockspecs/$_rockname-$pkgver-$_rockrel.rockspec"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua-cassowary() {
	_package 5.4
}

package_lua51-cassowary() {
	_package 5.1
}

package_lua52-cassowary() {
	_package 5.2
}

package_lua53-cassowary() {
	_package 5.3
}
